	subroutine shoreln4
	include 'cst.inc'
c
c	 this subroutine causes the shoreline to advance or retreat in sub-grid
c      increments.  it is based on the cowell and bruun idea that because the
c      time-scale of surf zone and uppermost shoreface profiles is very fast
c      they can be represented as having a fixed shape in long-term simulations
c      with the understanding that they are surrounded by an envelope of profiles
c      that represent the day-to-day conditions.  
c
c      the height change from subroutine exner is redistributed by this
c      subroutine between the beach/surf zone cell (jshore(i)) and the 
c      adjoining cells in the j-direction because the fixed profile shape 
c	 (represented by a sloped straight line) slides in, or out (not up
c      or down) as the jshore(i) cell empties or fills. as this profile
c      'slides' in or out sand volume is subtracted or added to the
c      adjacent cells accordingly. the cell seaward of jshore(i) also
c      adjusts; coming up as the beach/surf zone profile advances or
c      going down in the retreating condition.
c
c	 when this 'sliding' of the profile causes the shoreline to move 
c      to one of the adjacent cells the values of jshore(i) is changed
c      accordingly.
c
c
c    begin loop covering all "i"s
c
	dh=htop-hbot
	do i=1,imax
	   jj=jshore(i)
         hinc=h(i,jj)-hold(i)
		 spread=h(i,jj)-h(i,jj-1)
	   if(hinc.gt.0.and.spread.gt.dh) then
	     h(i,jj)=h(i,jj)-hinc
	     h(i,jj-1)=h(i,jj-1)+hinc
	   endif
   	   hinc=h(i,jj)-hold(i)
    	   if(hinc.ge.0.and.h(i,jj).ge.htop) then
           delh=h(i,jj)-htop
	     h(i,jj-1)=h(i,jj-1)+delh
	     h(i,jj)=h(i,jj)-delh
           jshore(i)=jj-1
	     jj=jshore(i)
c          yoff(i)=dy*(1-h(i,jj)/(dh))+(jj-1)*dy
           yoff(i)=deltay*(0.5-((h(i,jj)-hbot)/dh))  !new equation on 7/24/2009
	   elseif(hinc.lt.0.and.h(i,jj).le.hbot) then
           delh=h(i,jj)-hbot
	     h(i,jj+1)=h(i,jj+1)+delh
	     h(i,jj)=h(i,jj)-delh
           jshore(i)=jj+1
	     jj=jshore(i)
c      	   yoff(i)=dy*(1-h(i,jj)/(dh))+(jj-1)*dy
           yoff(i)=deltay*(0.5-((h(i,jj)-hbot)/dh))  !new equation on 7/24/2009
   	   else
c           yoff(i)=dy*(1-h(i,jj)/(dh))+(jj-1)*dy
           yoff(i)=deltay*(0.5-((h(i,jj)-hbot)/dh))  !new equation on 7/24/2009
	   endif
       	 hold(i)=h(i,jshore(i))
      enddo


	return
	end